import { globalModal } from "@/data";


/**
 * 显示删除确认对话框
 * @description 弹出一个确认删除的模态框,点击确定返回 resolve,点击取消返回 reject
 * @returns {Promise} 返回一个 Promise 对象
 * @example
 * try {
 *   await deleteConfirm();
 *   // 用户点击了确定,继续删除操作
 * } catch(err) {
 *   // 用户点击了取消
 * }
 */
const deleteConfirm = () => {
    return new Promise((resolve, reject) => {
        globalModal.methods.modal.confirm({
            title: "确认删除吗",
            centered: true,
            content: "删除后数据不可恢复",
            onOk: async () => {
                resolve()
            },
            onCancel: () => {
                reject()
            }
        })
    })
}


/**
 * 显示成功提示对话框
 * @param {string} msg - 提示信息内容
 * @description 使用全局 Modal 组件展示一个居中的成功提示框,标题固定为"提示"
 */
const successAlert = (msg) => {
    globalModal.methods.modal.success({
        centered: true,
        title: "提示",
        content: msg || "操作成功"
    })
}

const errorAlert = (msg) => {
    globalModal.methods.modal.error({
        centered: true,
        title: "提示",
        content: msg || "操作失败"
    })
}

const messageSuccess = (msg) => {
    globalModal.methods.message.success(msg)
}

const messageError = (msg) => {
    globalModal.methods.message.error(msg)
}




export {
    deleteConfirm, successAlert, errorAlert, messageError, messageSuccess
}